package logic

import (
	"box-ma-fresh/mysql/model"
	"context"

	"box-ma-fresh/boxrpc/boxrpc"
	"box-ma-fresh/boxrpc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type GoodsDetailLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewGoodsDetailLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GoodsDetailLogic {
	return &GoodsDetailLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 商品详情
func (l *GoodsDetailLogic) GoodsDetail(in *boxrpc.GoodsDetailRequest) (*boxrpc.GoodsDetailResponse, error) {
	// todo: add your logic here and delete this line

	var goods model.GoodsType
	err := goods.GoodsTypeDetail(model.DB, in.GoodsTypeId)
	if err != nil {
		return nil, err
	}

	return &boxrpc.GoodsDetailResponse{
		GoodsTypeId: int64(goods.ID),
		TypeName:    goods.TypeName,
	}, nil
}
